package drds.binlog.parse.log_position_manager;

import com.google.common.collect.MapMaker;
import drds.binlog.common.Authors;
import drds.binlog.common.position.LogPosition;
import drds.binlog.parse.exception.ParseException;
import drds.common.Author;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

@Author(name = Authors.LI_YANG)
public class MemoryLogPositionManager extends AbstractLogPositionManager
{

    @Setter
    @Getter
    private Map<String, LogPosition> destinationToLogPositionMap;

    @Override
    public void start()
    {
        super.start();
        destinationToLogPositionMap = new MapMaker().makeMap();
    }

    @Override
    public void stop()
    {
        super.stop();
        destinationToLogPositionMap.clear();
    }


    @Override
    public void persistLogPosition(String destination, LogPosition logPosition) throws ParseException
    {
        destinationToLogPositionMap.put(destination, logPosition);
    }

    @Override
    public LogPosition getLatestIndexBy(String destination)
    {
        return destinationToLogPositionMap.get(destination);
    }


}
